<?php

class cntrlmanagealbum implements viewController {

	private $area;
	private $side;
	private $dependencies = array("JavaScript" => array("facebox.js", "manageAlbum.js"), "CSS" => array("facebox.css"));
	private $pageName = "";
	private $userObj;
	private $thisID;
	private $managedGroups;
	
	public function __construct(user &$userObj){

		if( $userObj->getAccessLevel() == -1 ){
			header("Location: home");
			exit;
		}
		
		$this->side = new template('control.manageAlbum');
		$this->area = new template('area.manageAlbum');

		$this->userObj = $userObj;
		
		parse_str( $_GET['act'] );

		$albumInfo = album::getAlbum($id);

		$this->thisID = $id;

		$this->renderPage($id, $albumInfo);
		$this->renderImageList();
	}

	private function renderPage($id, $albumInfo){
		$id = (int)$id;		
		
		$this->area->replaceAll(array(
			"groupName" => $albumInfo['name'],
			"groupDescription" => $albumInfo['description'],
			"isID" => $albumInfo['isID']
		));
				
	}

	protected function renderImageList(){
		$myAlbums = album::getUserAlbums($this->userObj);

		$output = "";
		
		if(count($myAlbums) > 0){
			
			foreach($myAlbums as $album){
				if($this->thisID == $album['isID']){
					$output .= "<option value='" . $album['isID'] . "' selected='selected'>" . $album['name'] . "</option>\n";
				} else {
					$output .= "<option value='" . $album['isID'] . "'>" . $album['name'] . "</option>\n";
				}
			}
		
		}

		$this->side->replace('groupList', $output);
				
	}

	public function getSide(){
		return $this->side;
	}
	
	public function getArea(){
		return $this->area;
	}
	
	public function getDependencies(){
		return $this->dependencies;
	}

	public function getPageName(){
		return $this->pageName;
	}
	
	public function getTools(){
		return "";
	}

}

?>